<template>
  <div>
    <div class="tab-h" >
      <div class="tab-item" v-bind:class="[num == index ?'active' : '']" v-for="(item,index) in tabs" :key="index" @click="tab(index)">{{item}}</div>
    </div>
    <selfLiftOrder v-if="num == 0"></selfLiftOrder>
    <takeOutOrder v-if="num == 1"></takeOutOrder>
  </div>
</template>
<script>
import api from '@/utils/api'
import selfLiftOrder from "@/components/self_lift_order"
import takeOutOrder from "@/components/take_out_order"
import { mapState, mapActions ,mapGetters } from 'vuex'
export default {
  data () {
    return {
      tabs: ["自提", "外卖","点单"],
      tabContents: [],
      num: 0
    }
  },
  components: {
    selfLiftOrder,
    takeOutOrder
  },
  computed: {
    ...mapGetters([
      'user'
    ])
  },
  beforeMount() {
    console.log('beforeMount')
    if (!this.user || !this.user.id) {
      // 用户未授权
      let url = '../user/get_user_info?callback_url=../order/index'
      wx.redirectTo({
        url: url
      })
      return
    }
  },
  async mounted () {

  },
  methods: {
    tab(index) {
      this.num = index;
    },
  }
}
</script>

<style >
.tab-h{
  width: 100%;
  display: flex;
  flex-direction:row;
  line-height: 40px;
  height:40px;
  font-size: 20px;
  background: white;
  position: fixed;
  top:0;
  z-index: 1000;
}
.tab-item{
  width: 33%;
  display: inline-block;
  text-align: center;
}
.tab-item.active{
  position: relative;
}
.tab-item.active:after{
  content: "";
  display: block;
  height: 4px;
  width: 60px;
  background: #4F4F4F;
  position: absolute;
  bottom: 0;
  left:50%;
  transform: translate(-50%);
  border-radius: 1px;
}
.card{
  width: 90%;
  margin: 10px auto;
  background: white;
  border-radius: 5px;
}
</style>
